Skip to content

ext/intl: IntlNumberRangeFormatter::format() crash when the formatting fails. - #23198

Closed
devnexen wants to merge 3 commits into
php:masterfrom
devnexen:intl-rangeformatter-crashers
Closed

ext/intl: IntlNumberRangeFormatter::format() crash when the formatting fails.#23198
devnexen wants to merge 3 commits into
php:masterfrom
devnexen:intl-rangeformatter-crashers

Conversation

@devnexen

Copy link
Copy Markdown
Member

No description provided.

…g fails.

When formatFormattableRange() failed, the error was set (which throws, as
exceptions are force-enabled there) but execution fell through to
intl_charFromString(), which returns NULL for the bogus result, and the NULL
zend_string ended up in return_value as an IS_STRING zval. The engine then
dereferenced it while discarding the return value.

The conversion is now only attempted for a successful formatting and both
failure paths return early.

createFromSkeleton() had the same shape of defect without the crash: the
skeleton failure path threw and then still built a
LocalizedNumberRangeFormatter out of the failed skeleton, so it bails out
early as well.
format() reset the global error slot and the object one separately, and both
methods reset before parsing their parameters, so a TypeError also cleared the
state. Use intl_errors_reset(), which covers both slots, and reset once the
parameters are known to be good.
@devnexen devnexen changed the title Intl rangeformatter crashers ext/intl: IntlNumberRangeFormatter::format() crash when the formatting fails. Aug 10, 2026
@devnexen
devnexen marked this pull request as ready for review August 10, 2026 11:45
@devnexen
devnexen requested a review from LamentXU123 as a code owner August 10, 2026 11:45

@LamentXU123 LamentXU123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yet another error state bug :(

try {
$formatter->format([], 2);
} catch (TypeError $error) {
echo $error->getMessage(), PHP_EOL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo $error->getMessage(), PHP_EOL;
echo $error::class, ': ', $error->getMessage(), PHP_EOL;

IntlNumberRangeFormatter::IDENTITY_FALLBACK_RANGE
);
} catch (TypeError $error) {
echo $error->getMessage(), PHP_EOL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo $error->getMessage(), PHP_EOL;
echo $error::class, ': ', $error->getMessage(), PHP_EOL;


?>
--EXPECT--
IntlNumberRangeFormatter::format(): Argument #1 ($start) must be of type int|float, array given

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
IntlNumberRangeFormatter::format(): Argument #1 ($start) must be of type int|float, array given
TypeError: IntlNumberRangeFormatter::format(): Argument #1 ($start) must be of type int|float, array given

--EXPECT--
IntlNumberRangeFormatter::format(): Argument #1 ($start) must be of type int|float, array given
bool(true)
IntlNumberRangeFormatter::createFromSkeleton(): Argument #1 ($skeleton) must be of type string, array given

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
IntlNumberRangeFormatter::createFromSkeleton(): Argument #1 ($skeleton) must be of type string, array given
TypeError: IntlNumberRangeFormatter::createFromSkeleton(): Argument #1 ($skeleton) must be of type string, array given

@devnexen devnexen closed this in 2f08d44 Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants